package cn.big.bigd.biocode.dao;

import cn.big.bigd.biocode.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *@Author wangfan
 *@Date 2017/12/4 11:36
 */

@Repository
public interface UserDAO extends JpaRepository<User, Long> {
    @Query("SELECT CASE WHEN COUNT(u) > 0 THEN true ELSE false END FROM User u WHERE u.email = :email")
    boolean existsByEmail(@Param("email") String email);

    @Query(value = "SELECT  DISTINCT  users.* from curation,users where curation.user_id=users.id",nativeQuery = true)
    List<User>  findCurationUsers();
    User findByEmailOrUsername(String email, String username);

    List<User> findByEmailContains(String q);

    User findByEmail(String email);


}
